package pl.edu.mimuw.irs.rcp.controller.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;

import pl.edu.mimuw.irs.rcp.controller.editor.IWorkflowEditor;
import pl.edu.mimuw.irs.rcp.controller.editor.TokenGameEditor;
import pl.edu.mimuw.irs.rcp.controller.editor.input.TokenGameEditorInput;

public class TokenGameHandler extends AbstractHandler {

	// *** Attributes

	// *** Methods

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		// XXX : class cast exception
		IWorkflowEditor editor = (IWorkflowEditor)HandlerUtil.getActiveWorkbenchWindow(event)
				.getActivePage().getActiveEditor();

		
		try {
			TokenGameEditorInput input = new TokenGameEditorInput();
			input.setWorkflow(editor.getModel());
			HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
					.openEditor(input, TokenGameEditor.ID);
		} catch (PartInitException e) {
			e.printStackTrace();
		}

		
		return null;
	}
}
